package com.zhouzi.zhaoyang.ui.activity

import android.content.Intent
import android.text.TextUtils
import android.widget.Toast
import com.zhouzi.zhaoyang.R
import com.zhouzi.zhaoyang.base.BaseActivity
import com.zhouzi.zhaoyang.mvp.p.ModifyPWhActivityPresenter
import com.zhouzi.zhaoyang.mvp.v.IModifyPWActivityView
import kotlinx.android.synthetic.main.modify_pw_activity.*

class ModifyPWActivity : BaseActivity(),IModifyPWActivityView {
    override fun errorToken() {
        exitToLogin()
    }
    var p = ModifyPWhActivityPresenter()
    init {
        p.attachView(this)
    }

    override fun onDestroy() {
        super.onDestroy()
        p.detachView()
    }


    override fun updatePasswordSuccess() {
        var activity = Intent(this,LoginActivity :: class.java)
        startActivity(activity)
    }

    override fun updatePasswordFailed(msg: String) {
        Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show()

    }

    override fun showLoadDialog() {
        loadDialog.show()
    }

    override fun dismissLoadDialog() {
        loadDialog.dismiss()

    }
    override fun getLayoutId(): Int {
        return R.layout.modify_pw_activity
    }

    override fun initView() {
        viewClick()
    }

    private fun viewClick() {
        btnConnUsb.setOnClickListener {


            if ( TextUtils.isEmpty(etOldPW.text.toString() ) && TextUtils.isEmpty(etNewPW.text.toString())){
                Toast.makeText(mContext, "请输入合法的密码", Toast.LENGTH_SHORT).show()

            }else if (!etNewPW.text.toString().equals(etNewPWConfirm.text.toString())){
                Toast.makeText(mContext, "新密码两次必须输入相同内容！", Toast.LENGTH_SHORT).show()
            }else{
                var map = mutableMapOf(
                    Pair("oldPass",etOldPW.text.toString()),
                    Pair("newPass",etNewPW.text.toString())
                )
                p.updatePassword(map)
            }
        }

        tvApBtn.setOnClickListener {

            finish()

        }
    }


}
